import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';

class ValDataBaseLoader {
  static final ValDataBaseLoader _instance = ValDataBaseLoader._internal();

  factory ValDataBaseLoader() => _instance;

  static late Database _database;

  ValDataBaseLoader._internal();

  Future<Database> get database async {
    if (_database != null) return _database;

    _database = await _initDatabase();
    return _database;
  }

  Future<Database> _initDatabase() async {
    final dbPath = await getDatabasesPath();
    final path = join(dbPath, 'cs_database.db');

    return await openDatabase(
      path,
      version: 1,
      onCreate: (db, version) async {
        await db.execute(
          'CREATE TABLE user_post_table(id INTEGER PRIMARY KEY AUTOINCREMENT, '
              'accountId INTEGER, title TEXT, coverImage TEXT, image TEXT, category TEXT, content TEXT, followed TEXT)',
        );
      },
    );
  }
}
